#include "com_ctcowh_jnitest_JniUtil.h"

JNIEXPORT jobject JNICALL Java_com_ctcowh_jnitest_JniUtil_createJniObject
  (JNIEnv * env, jclass clz){

        //获取jniUtil类中的静态字段的值
        jfieldID sId = env->GetStaticFieldID(clz, "staticIntField", "I");
        jint sFieldValue = env->GetStaticIntField(clz, sId);

        //生成JniTest对象
        jclass JniTestClz = env->FindClass("com/ctcowh/jnitest/JniTest");
        jmethodID init = env->GetMethodID(JniTestClz, "<init>", "(I)V");
        jobject JniTestObj = env->NewObject(JniTestClz, init, 25);

        //调用JniTest对象身上的calledByJni（）方法
        jmethodID calledByJni = env->GetMethodID(JniTestClz, "calledByJni", "(I)I");
        jint result = env->CallIntMethod(JniTestObj, calledByJni, sFieldValue);

        //获取JniTest对象身上的intFiled字段的值,然后将值设置成result
        jfieldID mInitFieldId = env->GetFieldID(JniTestClz, "intFiled", "I");
        env->SetIntField(JniTestObj, mInitFieldId, result);

        return JniTestObj;

  }

